package com.atguigu.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.TravelItemMapper;
import com.atguigu.entity.PageResult;
import com.atguigu.entity.QueryPageBean;
import com.atguigu.pojo.TravelItem;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = TravelItemService.class)
@Transactional
public class TravelItemServiceImpl implements TravelItemService{
    @Autowired
    private TravelItemMapper travelItemMapper;
    //新增
    @Override
    public void save(TravelItem travelItem) {
        travelItemMapper.save(travelItem);
    }

    //分页
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<TravelItem> list = travelItemMapper.getTravelItemList(queryPageBean);
        PageInfo<TravelItem> pageInfo = new PageInfo<TravelItem>(list);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void deleteById(Integer id) {
        travelItemMapper.deleteById(id);
    }

    @Override
    public TravelItem findById(Integer id) {
        return travelItemMapper.findById(id);
    }

    @Override
    public void edit(TravelItem travelItem) {
        travelItemMapper.edit(travelItem);
    }

    @Override
    public List<TravelItem> findAll() {
        return travelItemMapper.findAll();
    }

    @Override
    public List<Integer> getTravelItemIdsByGid(Integer gid) {
        return travelItemMapper.getTravelItemIdsByGid(gid);
    }

}
